var layer;
var element;
var form;
var laydate;
var table;
var upload;
layui.use(['element','layer','laydate','form','table'], function(){
    layer = layui.layer;
    element = layui.element;
    form = layui.form;
    laydate = layui.laydate;
    table = layui.table;
    upload = layui.upload;
    //日期时间范围
    laydate.render({
        elem: '#registerTime'
        ,type: 'datetime'
        ,trigger: 'click' //时间时间为点击事件
        ,range: true
    });
    load();
    selAuditList("","","","",3);;
})
/**
 *  按钮  点击事件 刷新页面  返回  检索
 * */
function load(){
    //搜索按钮
    $("#indexBtn").bind('click',function(){
        var registerTime=$("input[name=registerTime]").val();
        var res1 = registerTime.slice(0, 19);
        var res2 = registerTime.slice(22, registerTime.length);

        var account=$("input[name=account]").val();
        var nickname=$("input[name=nickname]").val();
        $("#not_approved").attr('class',"layui-btn index_btnStats")
        $("#passed").attr('class',"layui-btn index_btnStats")
        $("#reject").attr('class',"layui-btn index_btnStats")
        selAuditList(res1,res2,account,nickname,3);
    })
    var i=true;
    //收起筛选，放下
    $("#put_screen").bind('click',function(){
        if(i){//判断i如果为true，则隐藏搜索，如果为false则展示搜索
            $("#selIndex").attr("style","display:none;");
            $(".div_list_title").attr('style',"margin-top: -84px;")
            $("#put_screen").html("<i class='layui-icon layui-icon-up ayui-font-9'></i>打开筛选")
            i=false;
        }else{
            $("#selIndex").attr("style","dispaly:block;");
            $(".div_list_title").attr('style',"margin-top: 0px;")
            $("#put_screen").html("<i class='layui-icon layui-icon-down ayui-font-9'></i>收起筛选")
            i=true;
        }
    })
    //刷新页面按钮
    $(".tit_btn").bind('click',function(){
        location.reload();
    });

}

//查询
function selAuditList(res1,res2,account,nickname,ind){
    $.post("/personnel/selAuditList", {res1:res1,res2:res2,account:account,nickname:nickname,ind:ind}, function (res) {
        userTab(res.data);
    });
}

function selAuditUserData(data){
    var btn;
    if(data.result==1){
        btn=['关闭','通过','驳回'];
    }else{
        btn=['关闭'];
    }
    var layer = layui.layer;
    layer.open({
        type:2,//弹出层的类型
        title:"审核列表详情",
        area:['800px','550px'],//弹出层大小
        shade:0,//设置遮罩
        offset:'auto',//设置遮罩的位置
        maxmin:true,
        //弹出层内容
        content :"/personnel/commodity/AuditList_layer_sel.html",
        btn:btn,
        yes:function(index,layero){
            layer.close(layer.index);
        },btn2:function(){
            updAuditUser(data.user_id,data.rid,data.id);
        },btn3:function(){
            delAuditUser(data.id)
        },success:function(layero,index){
            var obj = layero.find('iframe').contents();
            //账号
            obj.find("input[name=account]").val(data.account);
            //名称
            obj.find("input[name=nickname]").val(data.nickname);
            //电话
            obj.find("input[name=phone]").val(data.phone);
            //身份证
            obj.find("input[name=id_card]").val(data.id_card);
            //邮箱
            obj.find("input[name=email]").val(data.email);
            //真实姓名
            obj.find("input[name=real_name]").val(data.real_name);
            //出生日期
            obj.find("input[name=birth_date]").val(renderTime(data.birth_date));
            //个性签名
            obj.find("input[name=freestyle]").val(data.freestyle);
            //状态(2正常，3封停，4注销）
            if(data.status==2){
                obj.find("input[name=status]").val("正常");
            }else if(data.status==3){
                obj.find("input[name=status]").val("封停");
            }else if(data.status==4){
                obj.find("input[name=status]").val("注销");
            }
            //执行结果（1待审核，2已通过，3已驳回）
            if(data.result==1){
                obj.find("input[name=result]").val("待审核");
            }else if(data.result==2){
                obj.find("input[name=result]").val("已通过");
            }else if(data.result==3){
                obj.find("input[name=result]").val("已驳回");
            }
            //申请职位
            obj.find("input[name=position]").val(data.position);
            //申请时间
            obj.find("input[name=apply_date]").val(renderTime(data.apply_date));
        }
    })
}



//layui-table
function userTab(item){
    table.render({
        elem:"#userListTab",//容器
        title:"审核列表",
        data:item,
        toolbar:true,
        page:true,
        cols:cols
    });
}
//layui-table格式
var cols=[[//定义列
    {type:'checkbox',align:'center'},//复选框靠左
    {title:'序号',align:'center',templet:function(data){
            return data.LAY_INDEX;
        }},
    {field:"nickname",title:"用户姓名",align:'center'},
    {field:"account",title:"用户账号",align:'center'},
    {field:"position",title:"申请职位",align:'center'},
    {field:"phone",title:"电话",align:'center'},
    {field:"apply_date",title:"申请时间",align:'center',templet:function(data){
            return renderTime(data.apply_date) ;
        }},
    {field:"email",title:"邮箱",align:'center'},
    {field:"result",title:"申请状态",align:'center',templet:function(data){
            if(data.result==1){
                return "待审核";
            }else if(data.result==2){
                return "已通过";
            }else if(data.result==3){
                return "已驳回";
            }
        }}


]];